package com.google.code.jcooky.chat.server.queue;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.google.code.jcooky.chat.server.client.Client;

public class DataCenter {
	
	private Map<String, Client> dataCenter = new HashMap<String, Client>();
	
	public DataCenter() {
	}
	
	public Set<String> getIds() {
		return dataCenter.keySet();
	}
	
	public boolean exists(String id) {
		return dataCenter.keySet().contains(id);
	}
	
	
	public boolean register(Client client) {
		if(dataCenter.containsKey(client.getId())) return false;
		
		synchronized(dataCenter) {
			dataCenter.put(client.getId(), client);
		}
		
		return true;
	}
	
	public void release(String id) {
		synchronized(dataCenter) {
			dataCenter.remove(id);
		}
	}
	
	public Client getClient(String id) {
		return dataCenter.get(id);
	}
}
